//@flow

/**
 * 版本号
 */
import React, { Component } from 'react';
import { 
    View,
    Text,
    ViewStyle,
    StyleSheet,
 } from 'react-native';
import { connect } from "react-redux";
import {VersionState} from "./version.state";
import * as VersionAction from "./version.action";
import { Button } from 'antd-mobile-rn';

type Props = {

    style:ViewStyle,

    versionNumber :string,
    setupChecking:()=>{},
    getMetaInfo:()=>{},
}
class VersionNumber extends Component <Props,{}>{
    componentDidMount(){
        this.props.getMetaInfo()
    }
    render(){
        return (
            <View
                style={[this.props.style,styles.container]}>
                <Button onClick={()=>{this.props.setupChecking()}}>click</Button>
                <Text>{this.props.versionNumber}</Text>
            </View>
        )   
    }
}
const mapStateToProps = (state):Props=>{
    let versionState : VersionState = state.versionReducer;
    return {
        // versionNumber:`${state.metaAppVersion}.${state.metaLabel}`
        versionNumber:`${versionState.metaAppVersion}.${versionState.metaLabel}`
    }
}
const mapDispatchToProps = dispatch=>{
    return {
        setupChecking :()=>dispatch(VersionAction.setupChecking()),
        getMetaInfo   : ()=>dispatch(VersionAction.setupMetaVersion()),
        updateStatus  : ()=>dispatch(VersionAction.updateStatus()),
    }
}
VersionNumber = connect(mapStateToProps,mapDispatchToProps)(VersionNumber)
export {VersionNumber};

const styles = StyleSheet.create({
    container:{
        alignItems:'center',
        justifyContent: 'center',
        flex: 1,
    }
})